package com.diankangwo.dao.impl;

import com.diankangwo.dao.BrowseLogDAO;
import com.diankangwo.domain.BrowseLog;
import com.diankangwo.util.PageSupport;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class BrowseLogDAOImpl extends BaseDaoImpl<BrowseLog> implements BrowseLogDAO {

    @Override
    public PageSupport<BrowseLog> getUserByUid(String uid, String sort, int pageNo, int pageSize) {
        PageSupport<BrowseLog> blList = new PageSupport<>();
        blList = findPagination("from BrowseLog bl where bl.uid = ? order by " + sort, pageNo, pageSize, uid);
        if (blList == null || blList.getResultData().size() == 0) {
            return null;
        } else {
            return blList;
        }
    }

    @Override
    public List<BrowseLog> getUserByUidAndComm(String uid, Integer comm) {
        List<BrowseLog> bList = new ArrayList<>();
        PageSupport<BrowseLog> blList = new PageSupport<>();
        blList = findPagination("from BrowseLog bl where bl.uid = ? and bl.commodity_id=?", 1, Integer.MAX_VALUE, uid, comm);
        if (blList == null || blList.getResultData().size() == 0) {
            return bList;
        } else {
            bList = blList.getResultData();
            return bList;
        }
    }

}
